package cn.yl.caner.service;

import java.sql.SQLException;

import cn.yl.caner.dao.DelDao;
import cn.yl.caner.domain.DelData;
import cn.yl.caner.utils.MyDataSourceUtils;

public class DelService {
	
	public String rePassword(DelData deldata) {
		//对比密码
		 String password = null;
		 DelDao deldao = new DelDao();
			try {
				//获取连接，并设置事务
				MyDataSourceUtils.start();
				password = deldao.rePassword(deldata);
			} catch (SQLException e) {
				try {
					//失败回滚
					MyDataSourceUtils.rollback();
				} catch (SQLException e1) {
					System.out.println("事物回滚失败");
				}
				System.out.println("事物出现错误！");
			}finally {
				try {
					//提交事务
					MyDataSourceUtils.commit();
				} catch (SQLException e) {
					System.out.println("事物提交失败！");
				}
			}
		
		return password;
		 
	}

	
	public int delAccount(DelData deldata) {
		//service层，对删除信息提交事务，转换至DAO层
		 int i = 0;
		DelDao deldao = new DelDao();
			try {
				//获取连接，并设置事务
				MyDataSourceUtils.start();
				i = deldao.delAccount(deldata);
			} catch (SQLException e) {
				try {
					//失败回滚
					MyDataSourceUtils.rollback();
				} catch (SQLException e1) {
					System.out.println("事物回滚失败");
				}
				System.out.println("事物出现错误！");
			}finally {
				try {
					//提交事务
					MyDataSourceUtils.commit();
				} catch (SQLException e) {
					System.out.println("事物提交失败！");
				}
			}
		
		return i;
		 
	}
}

